#include "msgpage.h"
#include "ui_msgpage.h"
#include <QSplitter>
#include <QWindow>
#include <QScreen>

MsgPage::MsgPage(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MsgPage)
{
    ui->setupUi(this);
    
    // 设置初始分割比例（30:70）
    QList<int> sizes;
    sizes << width() * 0.3 << width() * 0.7;
    ui->splitter->setSizes(sizes);
    
    // 监听窗口状态变化
    connect(window()->windowHandle(), &QWindow::windowStateChanged,
            this, &MsgPage::onWindowStateChanged);
}

void MsgPage::onWindowStateChanged(Qt::WindowState state)
{
    QList<int> sizes;
    if (state == Qt::WindowMaximized) {
        // 最大化时调整为60:40
        sizes << width() * 0.6 << width() * 0.4;
    } else {
        // 其他状态保持30:70
        sizes << width() * 0.3 << width() * 0.7;
    }
    ui->splitter->setSizes(sizes);
}

MsgPage::~MsgPage()
{
    delete ui;
}
